<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <title>Array.from()</title>
  </head>
  <body>
    <p>Array.from()将类数组对象（可迭代的，包括map,set）转换为数组</p>
    <pre>
      let arrayLike = {
         '0':'a', 
         '1':'b', 
         '2':'c', 
         length:3
      }
      //ES5
      var arr1 = [].slice.call(arrayLike);
      //ES6
      var arr2=Array.from(arrayLike)
   </pre
    >
    <p>Array.from(arrayLike,callback) 第二个参数处理数组的每个元素</p>
    <pre>
     var arr3=Array.from(arrayLike,x=>x*x)
    </pre>
  </body>
</html>
<script>
  let arrayLike = {
    0: "a",
    1: "b",
    2: "c",
    length: 3,
  };
  //ES5
  var arr1 = [].slice.call(arrayLike);
  //ES6
  var arr2 = Array.from(arrayLike);
  var arr3 = Array.from(arrayLike, (x) => x * x);
</script>
